/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.hyjiacan.deadqq.client.window;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JLabel;

import org.hyjiacan.deadqq.client.i18n.I18N;
import org.hyjiacan.deadqq.common.util.WindowUtil;


/**
 * 关闭程序的确认对话框，当且仅当用户点击主窗口（用户成功登录后的窗口） 上面的关闭按钮时会显示。通过设置可以保存点击关闭按钮的作用（
 * 退出程序还是只是隐藏程序的主界面）。<br/>
 * 此类为单实例类，对话框为模式对话框，即当此对话框出现时，主界面不再接收事件。
 * 
 * @author hyjiacan
 */
public class CloseConfirmDialog extends JDialog {

	/**
	 * 
	 */
	private static final long serialVersionUID = 4024094660438968062L;
	private static CloseConfirmDialog instance;

	/**
	 * Creates new form CloseConfirmDialog
	 */
	private CloseConfirmDialog(java.awt.Frame parent, boolean modal) {
		super(parent, modal);
		initComponents();
                WindowUtil.center(this);
	}

	public static void showDialog() {
		if (instance == null) {
			instance = new CloseConfirmDialog(
					WindowManager.get(MainWindow.class.getName()), true);
		}
		instance.setVisible(true);
	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	// <editor-fold defaultstate="collapsed"
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        exitTip = new JLabel();
        saveSettings = new JCheckBox();
        no = new JButton();
        yes = new JButton();

        
        setTitle(I18N.getString("EXIT XX CONFIRM")); // NOI18N
        setResizable(false);

        exitTip.setText(I18N.getString("EXIT XX ?")); // NOI18N

        saveSettings.setText(I18N.getString("REMEMBER MY SETTINGS")); // NOI18N

        no.setText(I18N.getString("NO")); // NOI18N
        no.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                noActionPerformed(evt);
            }
        });

        yes.setText(I18N.getString("YES")); // NOI18N
        yes.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                yesActionPerformed(evt);
            }
        });

        GroupLayout layout = new GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(28, 28, 28)
                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(saveSettings)
                        .addGap(18, 18, 18)
                        .addComponent(no, GroupLayout.PREFERRED_SIZE, 67, GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(yes, GroupLayout.PREFERRED_SIZE, 67, GroupLayout.PREFERRED_SIZE))
                    .addComponent(exitTip))
                .addContainerGap(22, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(31, 31, 31)
                .addComponent(exitTip)
                .addGap(30, 30, 30)
                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                    .addComponent(saveSettings)
                    .addComponent(no)
                    .addComponent(yes))
                .addContainerGap(30, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

	private void noActionPerformed(ActionEvent evt) {// GEN-FIRST:event_noActionPerformed
		this.setVisible(false);
		WindowManager.get(MainWindow.class.getName()).setVisible(false);
	}// GEN-LAST:event_noActionPerformed

	private void yesActionPerformed(ActionEvent evt) {// GEN-FIRST:event_yesActionPerformed
		System.exit(0);
	}// GEN-LAST:event_yesActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private JLabel exitTip;
    private JButton no;
    private JCheckBox saveSettings;
    private JButton yes;
    // End of variables declaration//GEN-END:variables
}
